<?php
// +----------------------------------------------------------------------
// | xiongrui [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.xiongrui.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.xiongrui.cn>
// +----------------------------------------------------------------------

namespace app\common\model;


class Goodshops extends Base{

  protected $insert = ['status' => 1];

  public $addfield = array(
		array('name'=>'shopname','title'=>'商家名称','type'=>'text','help'=>''),
    array('name' => 'type', 'title' => '商品属性', 'help' => '', 'type' => 'radio', 'option' => ['0'=>'商家','1'=>'微商']),
		array('name'=>'address','title'=>'商家地址','type'=>'text','help'=>''),
		array('name'=>'shoplinkman','title'=>'联系人','type'=>'text','help'=>''),
		array('name'=>'shoptel','title'=>'联系电话','type'=>'text','help'=>''),
		array('name'=>'logo','title'=>'商家logo','type'=>'image','help'=>''),
		array('name'=>'rqcode','title'=>'商家二维码','type'=>'image','help'=>''),
		array('name'=>'winxin','title'=>'客服微信号','type'=>'text','help'=>''),
		array('name'=>'sort','title'=>'排序','type'=>'num','help'=>''),
		array('name'=>'status','title'=>'是否显示','type'=>'select','option'=>array('1'=>'是','0'=>'否'),'help'=>''),
    array('name'=>'dec','title'=>'商家介绍','type'=>'text','help'=>''),
    array('name'=>'shopremarks','title'=>'内容','type'=>'editor','help'=>''),
	);

  public function addfield(){
    //商家用户 group ID 为6
    $uids = AuthGroupAccess::where(['group_id'=>6])->column('uid');
    $bindingUids = array_filter(self::column('uid', 'id'));
    $users = User::where(['uid'=>['in', $uids]])->column('username', 'uid');
    //删除已绑定的uid
    foreach ($bindingUids as $key => $val){
        if($key != input('id')){
            unset($users[$val]);
        }
    }
    $users = [0=>'未绑定'] + $users;

    $field = array(
      array('name'=>'shopname','title'=>'商家名称','type'=>'text','help'=>''),
      array('name' => 'type', 'title' => '商品属性', 'help' => '', 'type' => 'radio', 'option' => ['0'=>'商家','1'=>'微商']),
  		array('name'=>'address','title'=>'商家地址','type'=>'text','help'=>''),
  		array('name'=>'shoplinkman','title'=>'联系人','type'=>'text','help'=>''),
  		array('name'=>'shoptel','title'=>'联系电话','type'=>'text','help'=>''),
  		array('name'=>'logo','title'=>'商家logo','type'=>'image','help'=>''),
  		array('name'=>'rqcode','title'=>'商家二维码','type'=>'image','help'=>''),
  		array('name'=>'winxin','title'=>'客服微信号','type'=>'text','help'=>''),
  		array('name'=>'sort','title'=>'排序','type'=>'num','help'=>''),
  		array('name'=>'status','title'=>'是否显示','type'=>'select','option'=>array('1'=>'是','0'=>'否'),'help'=>''),
      array('name'=>'dec','title'=>'商家介绍','type'=>'text','help'=>''),
      array('name'=>'uid','title'=>'绑定商家用户','type'=>'select','option'=>$users,'help'=>''),
      array('name'=>'shopremarks','title'=>'内容','type'=>'editor','help'=>''),
  	);

    return $field;
  }

}
